package com.medical.service.impl;

import com.medical.mapper.UsageTrendMapper;
import com.medical.pojo.TrendVO;
import com.medical.pojo.UsageTrend;
import com.medical.service.UsageTrendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class UsageTrendServiceImpl implements UsageTrendService {

    @Autowired
    private UsageTrendMapper usageTrendMapper;

    @Override
    public List<UsageTrend> findAll(TrendVO trendVO) {
        return usageTrendMapper.findAll(trendVO);
    }

    @Override
    public List<String> findUsageToday(TrendVO trendVO) {
        List<UsageTrend> list = usageTrendMapper.findAll(trendVO);
        List<String> usageToday = list.stream().map(UsageTrend::getUsageToday).collect(Collectors.toList());
        return usageToday;
    }

    @Override
    public List<String> findUsageYesterday(TrendVO trendVO) {
        List<UsageTrend> list = usageTrendMapper.findAll(trendVO);
        List<String> usageYesterday = list.stream().map(UsageTrend::getUsageYesterday).collect(Collectors.toList());
        return usageYesterday;
    }

    @Override
    public List<String> findJoint(TrendVO trendVO) {
        // 根据查询条件获取所有使用趋势对象
        List<UsageTrend> list = usageTrendMapper.findAll(trendVO);
        // 从每个使用趋势对象中提取连接点并收集到列表中
        List<String> jointList = list.stream().map(UsageTrend::getJoint).collect(Collectors.toList());
        return jointList;
    }
}
